const Router = require('koa-router');
const StudentCourseRouter = new Router();
const StudentCourseService = require('../service/StudentCourseService');
const R = require('../utils/R');
const Validators = require('../utils/validators');

StudentCourseRouter.prefix('/api/v1/studentcourse');

StudentCourseRouter.get('/list', async (ctx, next) => {
    let { pageSize, pageNum, status, studentId } = ctx.request.query;
    Validators.isNull(pageNum, 'pageNum').isNull(pageSize, 'pageSize')
    let data = await StudentCourseService.findCourseList(pageSize, pageNum, status, studentId);
    ctx.pageSize = pageSize;
    ctx.pageNum = pageNum;
    ctx.body = R.okData(data)
})

StudentCourseRouter.post('/save', async (ctx, next) => {
    let obj = ctx.request.body;
    Validators.isHave(obj.studentId, 'studentId').isNull(obj.courseId, 'courseId');
    await StudentCourseService.saveData(obj);
    ctx.body = R.okMsg('添加成功');
})

module.exports = StudentCourseRouter